﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using BlueHarvestSnippetGenerator.Pages;
using BlueHarvestSnippetGenerator.TutorialClasses.TutorialModel;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Snippets;

namespace BlueHarvestSnippetGenerator.TutorialClasses.TutorialController
{
    public class TutorialControl
    {
        private string _tutorialTitle;

        public enum TutorialSteps
        {
            Start,
            Completed,
            Current,
            Previous,
            Next,
            Error
        }

        public TutorialSteps TutorialStep { get; set; }
        public TutorialParser TutorialParser { get; set; }
        private Tutorial TutorialInformation { get; set; }
        private TextDocument textDocument;

        private int StepCount=0;


        public string UserAnswer { get; set; }

        public List<string> TutorialStepList
        {
            get { return TutorialInformation.Steps; }
        } 

        public List<string> TutorialAnswerList
        {
            get { return TutorialInformation.Answers; }
        }

        public int MaxSteps
        {
            get { return TutorialInformation.Steps.Count; }
        }


        public TextEditor AvolonTutorialText
        {
            get
            {
                return TutorialPage.DisplayTutorialText;
            }
            set
            {
                
                TutorialPage.DisplayTutorialText = value;
            }
        }

        public TutorialPage TutorialPage { get; set; }


        public TutorialControl(TutorialPage test)
        {
            TutorialStartUp(test);
        }

        private void TutorialStartUp(TutorialPage test)
        {
            TutorialParser = new TutorialParser();

            TutorialPage = test;

            TutorialInformation = TutorialParser.CreateTutorial();

            TutorialStep = TutorialSteps.Start;

            TutorialPage.txbTitle.Text = TutorialInformation.Title;
            
            

        }

        public void StartTutorial()
        {
            AvolonTutorialText.AppendText(TutorialStepList[StepCount]);
        }

        public void FinisehdTutorial()
        {
            AvolonTutorialText.AppendText(TutorialStepList[MaxSteps-1]);
            
        }

        public void Stepper()
        {


            var temp = TutorialStepList[StepCount].Split(':');

            string holder = string.Empty;

            foreach (string s in temp)
            {
                holder += s.Trim() + Environment.NewLine;

            }
            AvolonTutorialText.AppendText(holder);
            //AvolonTutorialText.AppendText("/*"+TutorialStepList[StepCount] + Environment.NewLine + TutorialStepList[StepCount]+"*/");

          

            StepCount++;

        }
        public void appender(string val)
        {
            
            AvolonTutorialText.AppendText(val);
        }

        
    }
}
